package com.landi.carkey.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.avos.avoscloud.AVUser;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.landi.carkey.MainActivity;
import com.landi.carkey.R;

/**
 * @Description {欢迎页面}
 * @Creator wushan
 * @Date 2016/12/28 18:19
 */

public class LauncherActivity extends Activity {
    private  ImageView imageView;
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //全屏显示welcome画面
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_launcher);
        imageView = (ImageView)findViewById(R.id.iv_launcher);
        Glide.with(this).load(R.drawable.icon_launch).asGif().diskCacheStrategy(DiskCacheStrategy.SOURCE).into(imageView);

        final AVUser currentUser = AVUser.getCurrentUser();
        //延迟1.5秒后执行run方法中的页面跳转
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                if (currentUser != null) {
                    // 跳转到首页
                    Intent intent = new Intent(LauncherActivity.this, MainActivity.class);
                    startActivity(intent);
                } else {
                    //缓存用户对象为空时，可打登录界面
                    Intent intent = new Intent(LauncherActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
                LauncherActivity.this.finish();
            }
        }, 1500);
    }
}
